﻿// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "Custom/PassTest" {
    Properties{
        _MainTex("Base (RGB)", 2D) = "white" {}
    }

        CGINCLUDE

#include "UnityCG.cginc"

        sampler2D _CameraDepthTexture;
    uniform sampler2D _MainTex;

    struct v2f {
        float4 pos : SV_POSITION;
        float4 scrPos:TEXCOORD0;
        float2 uv : TEXCOORD1;
    };
    //Vertex Shader
    v2f vert(appdata_base v) {
        v2f o;
        o.pos = UnityObjectToClipPos(v.vertex);
        o.scrPos = ComputeScreenPos(o.pos);
        o.uv = v.texcoord.xy;
        return o;
    }

    //Reverse frag
    float4 fragReverse(v2f i) :COLOR{
        fixed4 col = tex2D(_MainTex, i.uv);
    // just invert the colors
    col = 1 - col;
    return col;
    }
        //Dept frag
        float4 fragDepth(v2f i) :COLOR{
            float depthValue = 1 - Linear01Depth(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.scrPos)).r);
            return float4(depthValue, depthValue, depthValue, 1.0f);
    }

        ENDCG

        Subshader {
        Tags{ "RenderType" = "Opaque" }
            //Pass 0
            Pass{
                ZTest Always Cull Off ZWrite Off
                Fog{ Mode off }

                CGPROGRAM
                #pragma glsl
                #pragma fragmentoption ARB_precision_hint_fastest
                #pragma vertex vert
                #pragma fragment fragReverse
                #pragma target 3.0
                ENDCG
        }
            //Pass 1
            Pass{
                ZTest Always Cull Off ZWrite Off
                Fog{ Mode off }

                CGPROGRAM
                #pragma glsl
                #pragma fragmentoption ARB_precision_hint_fastest
                #pragma vertex vert
                #pragma fragment fragDepth
                #pragma target 3.0
                ENDCG
        }
    }

    Fallback "Diffuse"
}